package com.jzzz.onenotification;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;



public class NotificationActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notification);


        findViewById(R.id.btn_open).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (NotificationUtil.requestPermissions(NotificationActivity.this)) {
                    NotificationUtil.startForegroundService(NotificationActivity.this, NotificationService.class);
                }
            }
        });

        findViewById(R.id.btn_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(NotificationActivity.this, NotificationService.class);
                stopService(intent);
            }
        });

    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (NotificationUtil.requestPermissions(this)) {
            NotificationUtil.startForegroundService(this, NotificationService.class);
        }
    }
}